# Contributor: knuxify <knuxify@gmail.com>
# Maintainer: knuxify <knuxify@gmail.com>
pkgname=pigpio
pkgver=79
pkgrel=2
pkgdesc="C library for the Raspberry Pi which allows control of the GPIO"
url="https://abyz.me.uk/rpi/pigpio/"
arch="armhf armv7 aarch64" # only runs on the Raspberry Pi
license="Unlicense"
makedepends="cmake py3-setuptools samurai"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-openrc
	py3-$pkgname:_python:noarch
	"
install="$pkgname.post-install"
source="https://github.com/joan2937/pigpio/archive/refs/tags/v$pkgver/pigpio-$pkgver.tar.gz
	pigpiod.initd"
options="!check" # tests require GPIO access

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=Release \
		$CMAKE_CROSSOPTS .
	cmake --build build

	python3 setup.py build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	mkdir -p "$pkgdir"/usr/share
	mv "$pkgdir"/usr/man "$pkgdir"/usr/share/man

	mkdir -p "$pkgdir"/etc/init.d
	install -Dm755 "$srcdir"/pigpiod.initd "$pkgdir"/etc/init.d/pigpiod

	python3 setup.py install --skip-build --root="$pkgdir"
}

_python() {
	pkgdesc="$pkgdesc (python bindings)"
	depends="python3"

	# rename
	provides="$pkgname-python=$pkgver-r$pkgrel"
	replaces="$pkgname-python"

	amove usr/lib/python3*
}

sha512sums="
bae24b0a28b6865bf4e0903d9e1881344ab7cf26a513f295d178402a426f90f2fdd43444cfe899c0bc25939a129ebf47ecd1ac1600683cd648902d56825a3203  pigpio-79.tar.gz
04ebf3ef5b740e694509f134305630f87d76c1c8651df50e83083c0c74b5946e17d601df2d192c034aeaa5f11d6fc3ae3a0579ff58a2073cdb4e45475b128054  pigpiod.initd
"
